package com.ruoyi.zxjd.work.service.impl;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.zxjd.work.domain.WorkTemplateTable2;
import com.ruoyi.zxjd.work.domain.bo.WorkProgressBO;
import com.ruoyi.zxjd.work.mapper.WorkTemplateTable2Mapper;
import com.ruoyi.zxjd.work.service.ICommonWorkTemplateTableService;
import com.ruoyi.zxjd.work.service.IWorkTemplateTable2Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * 运用“四种形态”纪律审查情况Service业务层处理
 * 
 * @author lcc
 * @date 2021-02-22
 */
@Service
public class WorkTemplateTable2ServiceImpl implements IWorkTemplateTable2Service {
    @Autowired
    private WorkTemplateTable2Mapper workTemplateTable2Mapper;
    @Autowired
    private WorkProgressServiceImpl workProgressService;
    @Autowired
    private ICommonWorkTemplateTableService commonWorkTemplateTableService;
    /**
     * 查询运用“四种形态”纪律审查情况
     * 
     * @param id 运用“四种形态”纪律审查情况ID
     * @return 运用“四种形态”纪律审查情况
     */
    @Override
    public WorkTemplateTable2 selectWorkTemplateTable2ById(Long id) {
        return workTemplateTable2Mapper.selectWorkTemplateTable2ById(id);
    }

    /**
     * 查询运用“四种形态”纪律审查情况列表
     * 
     * @param workTemplateTable2 运用“四种形态”纪律审查情况
     * @return 运用“四种形态”纪律审查情况
     */
    @Override
    public List<WorkTemplateTable2> selectWorkTemplateTable2List(WorkTemplateTable2 workTemplateTable2) {
        return workTemplateTable2Mapper.selectWorkTemplateTable2List(workTemplateTable2);
    }

    /**
     * 新增运用“四种形态”纪律审查情况
     * 
     * @param workTemplateTable2 运用“四种形态”纪律审查情况
     * @return 结果
     */
    @Transactional
    @Override
    public int insertWorkTemplateTable2(WorkProgressBO workProgressBO) {

        commonWorkTemplateTableService.insertOrUpdate(workProgressBO,"getWorkTemplateTable2", workTemplateTable2Mapper);

        return workProgressService.validate(workProgressBO.getWorkProgress());
    }

    /**
     * 修改运用“四种形态”纪律审查情况
     * 
     * @param workTemplateTable2 运用“四种形态”纪律审查情况
     * @return 结果
     */
    @Override
    public int updateWorkTemplateTable2(WorkTemplateTable2 workTemplateTable2) {
        workTemplateTable2.setUpdateBy(ShiroUtils.getLoginName());
        workTemplateTable2.setUpdateTime(DateUtils.getNowDate());
        return workTemplateTable2Mapper.updateWorkTemplateTable2(workTemplateTable2);
    }

    /**
     * 删除运用“四种形态”纪律审查情况对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteWorkTemplateTable2ByIds(String ids) {
        return workTemplateTable2Mapper.deleteWorkTemplateTable2ByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除运用“四种形态”纪律审查情况信息
     * 
     * @param id 运用“四种形态”纪律审查情况ID
     * @return 结果
     */
    @Override
    public int deleteWorkTemplateTable2ById(Long id) {
        return workTemplateTable2Mapper.deleteWorkTemplateTable2ById(id);
    }

    /**
     * 查询运用“四种形态”纪律审查情况
     * 
     * @param progressId
     * @return 运用“四种形态”纪律审查情况
     */
    @Override
    public WorkTemplateTable2 selectWorkTemplateTable2ByProgressId(Long progressId) {
        return workTemplateTable2Mapper.selectWorkTemplateTable2ByProgressId(progressId);
    }

    /**
     * 查询运用“四种形态”纪律审查情况
     * 
     * @param arrangeId
     * @return 运用“四种形态”纪律审查情况
     */
    @Override
    public Map<String,Object> selectWorkTemplateTable2ByArrangeId(Long arrangeId){
        Map<String,Object> resultMap = new HashMap<>();
        Map<String,Object> map = workTemplateTable2Mapper.selectWorkTemplateTable2ByArrangeId(arrangeId);
        Set<String> set = map.keySet();
        Iterator<String> iterator = set.iterator();
        while(iterator.hasNext()){
            String key = String.valueOf(iterator.next());
            String value = String.valueOf(map.get(key));
            value = StringUtils.equals("0", value)?"":value;
            resultMap.put(key, value);
        }
        return resultMap;
    }

}
